package com.beiye.drivertransport.adapter;

import android.content.Context;
import android.widget.TextView;

import com.beiye.drivertransport.R;
import com.beiye.drivertransport.bean.HomeNewsListViewBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by ky on 2017/12/29.
 */

public class MessageHomeApt extends ListBaseAdapter<HomeNewsListViewBean.RowsBean> {

    protected Context context = null;


    public MessageHomeApt(Context context){
        super(context);
        this.context = context;
    }

    @Override
    public int getLayoutId() {
        return  R.layout.home_message_item;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder,final int position) {
        TextView tv_title = holder.getView(R.id.tv_notice);
        TextView tv_mark = holder.getView(R.id.tv_notice2);
        TextView tv_date = holder.getView(R.id.tv_notice3);

        String noticeTitle = getDataList().get(position).getNoticeTitle();
       if(noticeTitle==null)
       {
           tv_title.setText("");
       }else{
           tv_title.setText(noticeTitle);
       }
        int viewMark = getDataList().get(position).getViewMark();
       if(viewMark==1)//已查看
       {
           tv_mark.setText("已读");
           tv_mark.setTextColor(context.getResources().getColor(R.color.cartext));
       }else{
           tv_mark.setText("未读");
           tv_mark.setTextColor(context.getResources().getColor(R.color.holetotal_red));
       }
        long creationDate = getDataList().get(position).getCreationDate();
        if (creationDate > 0) {
            Date date = new Date(creationDate);
            String creation="";
            try {
                //yyyy表示年MM表示月dd表示日
                //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                //进行格式化
                creation = sdf.format(date);
                tv_date.setText(creation);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            tv_date.setText("");

        }
    }






}